/*
 * Copyright 2011 myTDev.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mytdev.commons.util.messages;

public class Message {

    private String title;
    private String message;
    private Type type;

    public Message() {
    }

    public Message(String message, Type type) {
        this(null, message, type);
    }

    public Message(String title, String message, Type type) {
        this.title = title;
        this.message = message;
        this.type = type;
    }

    public String getMessage() {
        return message;
    }

    public String getTitle() {
        return title;
    }

    public Type getType() {
        return type;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public static enum Type {

        ERROR,
        INFORMATION,
        PLAIN,
        SUCCESS,
        WARNING;
    }

    public static Message error(String message) {
        return new Message(message, Type.ERROR);
    }

    public static Message error(String title, String message) {
        return new Message(title, message, Type.ERROR);
    }

    public static Message error(String title, Throwable throwable) {
        java.io.Writer writer = new java.io.StringWriter();
        throwable.printStackTrace(new java.io.PrintWriter(writer));
        return new Message(title, writer.toString(), Type.ERROR);
    }

    public static Message error(Throwable throwable) {
        java.io.Writer writer = new java.io.StringWriter();
        throwable.printStackTrace(new java.io.PrintWriter(writer));
        return new Message(writer.toString(), Type.ERROR);
    }

    public static Message info(String message) {
        return new Message(message, Type.INFORMATION);
    }

    public static Message info(String title, String message) {
        return new Message(title, message, Type.INFORMATION);
    }

    public static Message plain(String message) {
        return new Message(message, Type.PLAIN);
    }

    public static Message plain(String title, String message) {
        return new Message(title, message, Type.PLAIN);
    }

    public static Message success(String message) {
        return new Message(message, Type.SUCCESS);
    }

    public static Message success(String title, String message) {
        return new Message(title, message, Type.SUCCESS);
    }

    public static Message warn(String message) {
        return new Message(message, Type.WARNING);
    }

    public static Message warn(String title, String message) {
        return new Message(title, message, Type.WARNING);
    }
}
